package cemetery.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import cemetery.bean.customer;
import cemetery.bean.park;
import cemetery.dao.BaseDao;
import cemetery.dao.parkDao;

public class ParkDaoImpl extends BaseDao implements parkDao {
	@Override
	public List<customer> getList(customer news) {
		Connection conn=null;
		PreparedStatement stmt=null;
		ResultSet rs=null;
		List<customer>list=new ArrayList<customer>();
		try {
			conn=getconnection();
			String sql=" SELECT customer.`id`, park.`name`,park.addres,customer.`name`,customer.phone, burial "
					+ " FROM customer,park WHERE customer.park=park.id  ";
			if (news!=null && news.getId()!=0) {
				sql=sql+" and customer.id='"+news.getId()+"' ";
			}
			if (news!=null && news.getName()!=null&& !"".equals(news.getName())) {
				sql=sql+" and customer.name like '%"+news.getName()+"%' ";
			}
			stmt=conn.prepareStatement(sql);
			rs=stmt.executeQuery();
			while (rs.next()) {
				customer cs=new customer();
				cs.setId(rs.getInt(1));
				cs.setYqname(rs.getString(2));
				cs.setAddres(rs.getString(3));
				cs.setName(rs.getString(4));
				cs.setPhone(rs.getString(5));
				cs.setBurial(rs.getInt(6));
				list.add(cs);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally {
			this.closeAll(conn, stmt, rs);
		}
			return list;
	}
}
